package _1Cookie;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/showcookie")
public class ShowCookieServlet extends HttpServlet{
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		// 1. 获取Cookie
		Cookie[] cookies = req.getCookies();
		
		resp.getWriter().print("cookie信息:<br />");
		if(cookies!=null)
		{
			for(Cookie c:cookies)
			{
				resp.getWriter().print(c.getName()+":"+c.getValue());
			}
		}
		
		
		// 练习
		// 1. 编写一个CountServlet，显示当前用户是第几次访问
		// 通过cookie保存第几次，
		//    第一次访问 没有次数信息  次数=1  放入cookie
		//    之后访问  从cookie中 读取出次数 +1  再次放入cookie
		
		
	}

}